package com.ht.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ht.domain.bo.TbHospitalBO;
import com.ht.domain.po.TbCities;
import com.ht.domain.po.TbHospital;
import com.ht.domain.vo.TbHospitalVO;
import com.ht.mapper.TbCittesMapper;
import com.ht.mapper.TbDoctorMapper;
import com.ht.mapper.TbHospitalMapper;
import com.ht.service.TbCittesService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TbCittesServiceImpl implements TbCittesService {
    @Autowired
    private TbCittesMapper tbCittesMapper;

    @Autowired
    private TbDoctorMapper tbDoctorMapper;

    @Autowired
    private  TbHospitalMapper tbHospitalMapper;


    @Override
    public  List<TbHospitalBO> queryProvincesByprocincesId(Long provinceId) {
        QueryWrapper q = new QueryWrapper();
        q.eq("province_id",provinceId);
        List<TbCities> list = tbCittesMapper.selectList(q);
        List<TbHospitalBO> listt = new ArrayList<>();
        list.forEach(obj->{
            QueryWrapper qq = new QueryWrapper();
            qq.eq("ctiy_id",obj.getId());
            List<TbHospital> list1 = tbHospitalMapper.selectList(qq);
            list1.forEach(objj->{
                TbHospitalBO bo = new TbHospitalBO();
                BeanUtils.copyProperties(objj,bo);
                listt.add(bo);
            });
        });
        return listt;
    }

    @Override
    public  List<TbHospitalBO> queryProvincesByCityId(Long cityId) {
        List<TbHospitalBO> listt = new ArrayList<>();
        QueryWrapper qq = new QueryWrapper();
        qq.eq("ctiy_id",cityId);
        List<TbHospital> list1 = tbHospitalMapper.selectList(qq);
        list1.forEach(objj->{
            TbHospitalBO bo = new TbHospitalBO();
            BeanUtils.copyProperties(objj,bo);
            listt.add(bo);
        });
        return listt;
    }
}
